package com.bootdo.system.utils;

import java.math.BigDecimal;

public class CalUtil {

    public static BigDecimal calPercentAbs(BigDecimal front,BigDecimal end){
        if(front==null||front.compareTo(BigDecimal.ZERO)==0){
            return BigDecimal.ZERO;
        }
        if(end==null||end.compareTo(BigDecimal.ZERO)==0){
            return BigDecimal.ZERO;
        }
        //减去
        BigDecimal subtract = front.subtract(end);
        //bili
        BigDecimal divide = subtract.divide(end, 6, BigDecimal.ROUND_UP);
        //绝对值
        BigDecimal abs = divide.abs();
        return  abs;

    }

    public static BigDecimal calPercent(BigDecimal front,BigDecimal end){
        if(front==null||front.compareTo(BigDecimal.ZERO)==0){
            return BigDecimal.ZERO;
        }
        if(end==null||end.compareTo(BigDecimal.ZERO)==0){
            return BigDecimal.ZERO;
        }
        //减去
        BigDecimal subtract = front.subtract(end);
        //bili
        BigDecimal divide = subtract.divide(end, 6, BigDecimal.ROUND_UP);


        return  divide;

    }

}
